package com.liuyang.service.impl;

import cn.hutool.core.map.MapBuilder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liuyang.entity.Carouselimg;
import com.liuyang.mapper.CarouselimgMapper;
import com.liuyang.service.CarouselimgService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 作者:caleb
 * @since 2022-03-03
 */
@Service
public class CarouselimgServiceImpl extends ServiceImpl<CarouselimgMapper, Carouselimg> implements CarouselimgService {

    @Autowired
    private CarouselimgMapper carouselimgMapper;

    @Override
    public Map<String, Object> queryCarouseInfo(int page, int limit) {
        QueryWrapper<Carouselimg> queryWrapper = new QueryWrapper<>();
        Page<Carouselimg> carouselimgPage = new Page<>(page, limit);
        IPage<Carouselimg> carouselimgIPage = carouselimgMapper.selectPage(carouselimgPage, queryWrapper);
        long total = carouselimgIPage.getTotal();
        List<Carouselimg> records = carouselimgIPage.getRecords();
        MapBuilder<String, Object> mapBuilder = MapBuilder.create();
        Map<String, Object> map = mapBuilder.put("total", total).put("records", records).build();
        return map;
    }
}
